<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
    <template id="pengfan">
        <div>
            <h2>{{counter}}</h2>
            <button @click="increment">点击了+1</button>
            <button @click="decrement">点击了-1</button>
            <button @click="btnClick">按钮</button>
        </div>
    </template>

    <script src="../js/vue.js"></script>
    <script>
        Vue.createApp({
            template: "#pengfan",
            data: function () {
                return {
                    counter: 100,
                }
            },
            methods: {
                increment() {
                    this.counter++;
                },
                decrement() {
                    this.counter--;
                },
                btnClick() {
                    // this === window? 不可以
                    // 写成一个箭头函数时，这个this就是window
                    // 在箭头函数中是不绑定this的，但是函数中使用this，this往上级作用域找
                    console.log(this)
                }
            }

        }).mount("#app")
    </script>
</body>

</html>